home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9819 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.netam.net!alpha!bgc
  2. From: bgc@alpha.netam.net (The Bowling Green Connection)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! Modifying the EOF in a file!
  5. Date: 13 Mar 1996 20:05:01 GMT
  6. Organization: NetAmerica, Bowling Green, KY.
  7. Distribution: world
  8. Message-ID: <4i79pd$slk@news.netam.net>
  9. References: <4i585k$4ia@news.netam.net> <4i5pb4$fae@sparcserver.lrz-muenchen.de>
  10. NNTP-Posting-Host: alpha.netam.net
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. ua302aa@lrz-muenchen.de wrote:
  14. : I fail to see where you want to _write_ to "file.txt"
  15.  
  16. The whole situation is rather involved, so I stuck to 
  17. simplicity.. but if you want to know the whole
  18. situation, here it is:
  19.  
  20. I have a queue set up on the internet to mail mime-format
  21. messages to myself (there is a reason why, but it's
  22. too long for me to explain now).  Basically, from a 
  23. browser you can click a submit button which will call
  24. this SendMail procedure.  The procedure extracts information
  25. from the fillout form on the page and creates a text file
  26. under the name of mime.body in Unix.
  27.  
  28. Now, since it is possible for two or more people to submit
  29. messages at the same time, I have to make sure that the
  30. mime.body file is locked (I use the flock() procedure)
  31. while data is being written to it, and while it is being
  32. mailed with the mailto command (which can send mime-
  33. formatted messages).  So everyone else must wait until
  34. the file becomes unlocked before their message gets
  35. queued up for mailing. 
  36.  
  37. The way I send the message in mime format is by making
  38. a system call that runs an environment command and
  39. runs the mailto command, which has piped to it the
  40. contents of a file called mime.wrap, which references
  41. the mime.body (with mailto's special formatting
  42. language) file.  SO... If I want to send a mime message,
  43. I first have to have the mime.body file in place and
  44. ready to go.  I can't just fopen("newfile", "w").
  45. I have to modify the old file and possibly have to
  46. shorten it.  The ftruncate() procedure will work
  47. for me here, and I thank all of you for pointing me
  48. in the right direction!
  49.  
  50. The only thing that still bothers me is my method for
  51. locking the file.  I have to figure out a way to keep
  52. other processes from editing the mime.body file UNTIL
  53. the mailto command gets finished mailing the thing
  54. off! 
  55.  
  56. Can I keep the file open (and locked), call a fflush(),
  57. and send the mail before closing it?  This is one
  58. way I could maintain the lock on the file, because I
  59. understand that if I close the file, the lock is 
  60. removed.
  61.  
  62. Eddie,
  63. bgc@bgcky.com
  64.